c++
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N = 100004;
constexpr int M = 300005;
constexpr ll mod = 1e9 + 7;
void mul(ll&a ,ll b){
a=a*b%mod;
}
int head[N], to[M], nxt[M], tot = 0;
void add(int u, int v) {
nxt[++tot] = head[u];
head[u] = tot;
to[tot] = v;
}
int dfn[N], low[N], timer;
int scc[N], scc_cnt;
std::vector<int> stk;
bool in_stk[N];
struct edge {
int u, v;
} e[M];
struct node {
ll mn, mcnt;
} scc_node[N];
int n, m;
int c[N];
void tarjan(int u) {
dfn[u] = low[u] = ++timer;
stk.push_back(u);
in_stk[u] = true;
for (int i = head[u]; i; i = nxt[i]) {
int v = to[i];
if (!dfn[v]) {
tarjan(v);
low[u] = std::min(low[u], low[v]);
} else if (in_stk[v]) {
low[u] = std::min(low[u], dfn[v]);
}
}
if (dfn[u] == low[u]) {
++scc_cnt;
scc_node[scc_cnt].mn = mod;
int v;
do {
v = stk.back();
stk.pop_back();
in_stk[v] = false;
scc[v] = scc_cnt;
if (c[v] < scc_node[scc_cnt].mn) {
scc_node[scc_cnt].mn = c[v];
scc_node[scc_cnt].mcnt = 1;
} else if (c[v] == scc_node[scc_cnt].mn) {
scc_node[scc_cnt].mcnt++;
}
} while (v != u);
}
}
void fc() {
std::cin >> n;
for (int i = 1; i <= n; i++) std::cin >> c[i];
std::cin >> m;
for (int i = 0; i < m; i++) {
int u,v;std::cin>>u>>v;
add(u,v);
}
for (int i = 1; i <= n; i++)
if (!dfn[i]) tarjan(i);
ll sum = 0, cnt = 1;
for (int i = 1; i <= scc_cnt; i++) {
sum+=scc_node[i].mn;
mul(cnt,scc_node[i].mcnt);
}
std::cout << sum << " " << cnt;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// std::cin>>t;
while (t--) fc();
return 0;
}